import Vue from 'vue'
import api from '@api'
import App from './App.vue'
import store from '@/store'
import router from '@/router'
// import Url from '@/plugin/url'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import '@assets/style/common.css'
import * as echarts from 'echarts'

Vue.use(ElementUI)
// Vue.use(Url)
Vue.prototype.$api = api
Vue.prototype.$echarts = echarts
Vue.config.productionTip = false

let DiyPlugin = {}
DiyPlugin.install = function (Vue) {
  function parse (urlStr) {
    const re = /[?&]([^?&=]+)=([^&]+)/g
    let matcher = null
    const items = {}
    urlStr = urlStr || window.location.search
    while ((matcher = re.exec(urlStr)) !== null) {
      items[matcher[1]] = decodeURIComponent(matcher[2])
    }
    return items
  }
  const query = parse()
  Object.defineProperty(Vue.prototype, '$url', {
    get () { return { query } }
  })
}
Vue.use(DiyPlugin)

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
